package controller;

import core.BaseServlet;
import dao.LogDao;
import dao.impl.LogDaoImpl;
import pojo.Log;
import util.Result;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "LogServlet", urlPatterns = "/log")
public class LogServlet extends BaseServlet {

    private LogDao logDao = new LogDaoImpl();

    /**
     * 日志界面
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void logPage(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.getRequestDispatcher("/WEB-INF/pages/systemLog/log.jsp").forward(request, response);
    }

    /**
     * 获取所有日志
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    public void logList(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        List<Log> log = logDao.findLog();
        if (log==null){
            Result.response(1001, "查找失败", response);
            return;
        }
        Result.response(200, "查找成功！", response, log);
    }
}
